// pages/schoolnews/schoolnews.js
var app = getApp();
var ea = require('../../utils/each.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    getxiaoqumessage: app.data.url +'/zhongxue/maoapi/getxiaoqumessage',
    src: app.data.url +'/uploads/zhongxue/xiaoqunotice.png',
    page:1,
    shuju:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData();
  },
  getData:function(){
    var page = this.data.page;
    if(page==0){
      wx.showToast({
        title: '没有更多数据了',
        icon: 'none',
        duration: app.data.quanbushijian,
      })
      return
    }
    var that = this;
    var user = wx.getStorageSync('user');
    var xiaoqu = wx.getStorageSync('xiaoqu');
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: this.data.getxiaoqumessage,
      data: { xiaoqu: xiaoqu, token: user.token,page:page },
      method: "POST",
      success: function (res) {
        var data = res.data;
        console.log(data);
        if(data.code==200){
          var shuju = data.data;
          if(shuju.length<10){
            that.setData({page:0});
          }else{
            that.setData({ page: page+1 });
          }
          var newshuju = that.data.shuju;
            ea.each(shuju,function(i,v){
              newshuju.push(v);
            })
            console.log(newshuju);
          that.setData({ shuju: newshuju});
        }else{
          wx.showToast({
            title: data.msg,
            icon:'none',
            duration: app.data.quanbushijian,
          })
        }
        wx.hideLoading();
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      page: 1,
      shuju: []
    })
    this.getData();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
      this.getData();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})